//
//  UibarButtonItem+Extension.swift
//  weiBo---01
//
//  Created by 王—wagn on 16/4/11.
//  Copyright © 2016年 王—wagn. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(imageName : String? = nil,title : String? = nil,target : AnyObject,action : Selector )
    {
        self.init()
        let btn = UIButton()
        //图片类型
        customView = btn
        //判断图片是否存在
        if let name = imageName {
        btn.setTitle(title, forState: .Normal)
        btn.setImage(UIImage(named: name), forState: .Normal)
        btn.setImage(UIImage(named: name + "_highlighted"), forState: .Highlighted)
        }
        
        btn.addTarget(target, action: action, forControlEvents: .TouchUpInside)
        //设置字体
        btn.setTitle(title, forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(14)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.setTitleColor(UIColor.orangeColor(), forState: .Highlighted)
        
        btn.sizeToFit()
        
        
        
    }

}
 